package edu.cuit.avatar.collection;

import java.util.*;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/14 14:44
 */
public class CollectionTest {
    public static void main(String[] args) {
        Collection<String> c1 = new ArrayList<>();

        c1.add("Peppa");
        c1.add("Emily");

        Collection<String> c2 = new LinkedList<>();
        c2.add("Pedro");
        c2.addAll(c1);

        System.out.println(c1);
        System.out.println(c2);
        c1.clear();

        System.out.println(c2.contains("Candy"));
        System.out.println(c2.contains("Pedro"));//true

        //使用迭代器迭代c2集合
        Iterator<String> iterator = c2.iterator();
        while(iterator.hasNext()){
            String element = iterator.next();
            System.out.println(element);
        }

        System.out.println("==============================forEach内部使用迭代器进行迭代=====================");
        for(var e : c2)
            System.out.println(e);

        System.out.println("==============================");
        c2.forEach(System.out::println);
    }
}
